package com.kws.merchant.controller;


import com.kws.merchant.domain.Specification;
import com.kws.merchant.service.SpecificationService;
import com.kws.merchant.util.FileUtil;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import org.springframework.web.bind.annotation.*;
import com.kws.common.core.domain.R;

import javax.annotation.Resource;
import java.util.List;

/**
 * 规格信息表(Specification)表控制层
 *
 * @author yxy
 * @since 2024-10-22 11:09:11
 */
@RestController
@Api(tags = "规格信息表(Specification)")
@RequestMapping("specification")
public class SpecificationController {
    /**
     * 服务对象
     */
    @Resource
    private SpecificationService specificationService;


    @GetMapping("/detailById/{id}")
    @ApiOperation(value = "通过主键查询单条数据")
    public R<Specification> detailById(@PathVariable Long id) {
        return R.ok(specificationService.detailById(id));
    }


    @PostMapping("/add")
    @ApiOperation(value = "新增数据")
    public R add(@RequestBody Specification specification) {
        specification.setImg(FileUtil.subFileName(specification.getImg()));
        return R.ok(specificationService.save(specification));
    }

    @PostMapping("/update")
    @ApiOperation(value = "修改数据")
    public R update(@RequestBody Specification specification) {
        return R.ok(specificationService.updateById(specification));
    }


    @PostMapping("/delete")
    @ApiOperation(value = "删除数据")
    public R delete(@RequestBody List<Long> idList) {
        return R.ok(specificationService.removeByIds(idList));
    }


    @GetMapping("/listByType/{type}")
    @ApiOperation(value = "规格列表")
    public R<List<Specification>> listByType(@PathVariable Integer type) {
        return R.ok(specificationService.listByType(type));
    }
}
